import { reqUserLogin } from '@/api/user'
export default {
  namespaced: true,
  // 模块里面的额 state，需要用函数返回
  state: () => {
    return {

      profile: {
        id: '',
        token: '',
        nickname: '',
        avatar: '',
        mobile: ''
      }
    }
  },
  mutations: {
    // setUserId (state, userId) {
    //   state.profile.id = userId
    // }
    setProfile (state, newProfile) {
      state.profile = newProfile
    },
    // 清空数据
    clearProfile (state) {
      state.profile = {
        id: '',
        token: '',
        nickname: '',
        avatar: '',
        mobile: ''
      }
    }
  },
  actions: {
    async login (context, data) {
      const res = await reqUserLogin(data)
      console.log('vuex中res 是什么', res)
      context.commit('setProfile', res.result)
    }
  }
}
